package com.zg.common.dds;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DatabaseMetaData;

/**
 * @author Zxb
 */
@Component
@RequiredArgsConstructor
public class DbTypeUtil {
    private final DynamicDataSource dynamicDataSource;
    public String getDatabaseType() {
        try (Connection connection = dynamicDataSource.getConnection()) {
            DatabaseMetaData metaData = connection.getMetaData();
            String databaseProductName = metaData.getDatabaseProductName();
            return databaseProductName;
        } catch (Exception e) {
            e.printStackTrace();
            return "Unknown";
        }
    }
    public Boolean isMysql() {
        String str = getDatabaseType();
        return "MySQL".equals(str);
    }
    public Boolean isOracle() {
        String str = getDatabaseType();
        return "Oracle".equals(str);
    }
}
